package com.example.demo.controller;


import com.example.demo.entity.Table;
import com.example.demo.entity.Teacher;
import com.example.demo.mapper.TeacherMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

@Controller
@RequestMapping("/teacher")
public class TeacherController {

    @Autowired
    TeacherMapper teacherMapper;

    @RequestMapping("/showTeacher")
    public String getTeacher(){
        return "/teacher/showTeacher";
    }


    /**
     * 用requestParam获取参数
     * @return
     */
    @ResponseBody
    @RequestMapping("/getAllTeacher")
    public Table getAllTeacher(@RequestParam("page") int page,@RequestParam("limit") int limit){
        Table tab = new Table<Teacher>();
        //自定义查询方法
        tab.setData(teacherMapper.getTeacherPage((page-1)*limit, limit));
        //注意  count 一定要传所有数据的条数
        tab.setCount(teacherMapper.selectCount(null));
        return tab;
    }

    @ResponseBody
    @RequestMapping("/deleteTeacherById")
    public int deleteTeacherById(@RequestParam("id") int id){
        //返回数据库受影响的行数
        return teacherMapper.deleteById(id);

    }



}
